package com.example.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉ActionBar
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }
        setContentView(R.layout.activity_main);
        System.out.println("MainActivity执行onCreate...");
        //获取Button to_red_act_bt的实例
        Button to_red_act_bt = findViewById(R.id.to_red_act_bt);

        //跳转到RedActivity,点击事件监听逻辑
        to_red_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i1 = new Intent(MainActivity.this,RedActivity.class);
                 i1.putExtra("username","张三 ");
                 i1.putExtra("age",20);
                 i1.putExtra("msg","来自MainActivity");
                 startActivity(i1);
            }
        });
        //获取Button to_blue_act_bt的实例
        Button to_blue_act_bt = findViewById(R.id.to_blue_act_bt);
        //跳转到BlueActivity
        to_blue_act_bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                User user = new User();
                user.setName("李白");
                user.setAge(18);
                user.setClassName("计算机");

                Intent i2= new Intent(MainActivity.this,BlueActivity.class);
                Bundle bundle = new Bundle();

                bundle.putString("msg","来自MainActivity的消息");
                bundle.putSerializable("data",user);
                i2.putExtras(bundle);
                startActivity(i2);
            }
        });
        //跳转到TestActivity按钮的方法
         findViewById(R.id.to_test_act_bt).setOnClickListener(v->{
             Intent intent3 = new Intent(MainActivity.this, TestActivity.class);
             startActivityForResult(intent3,9999);
         });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        if (resultCode==1000&&requestCode==9999){
            String data = intent.getStringExtra("data");
            //日志打印结果
            Log.i("MainActivityTAG","收到返回的消息："+data);
        }

    }

    @Override
    protected void onStart() {
        super.onStart();

        System.out.println("MainActivity执行onStart...");
    }

    @Override
    protected void onResume() {
        super.onResume();
        System.out.println("MainActivity执行onResume...");
    }

    @Override
    protected void onPause() {
        super.onPause();
        System.out.println("MainActivity执行onPause...");
    }
    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("MainActivity执行onStop...");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        System.out.println("MainActivity执行onRestart...");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("MainActivity执行onDestroy...");
    }


}